package com.example.healthmanagement.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.healthmanagement.pojo.ChildSportRecords;
import com.example.healthmanagement.service.ChildSportRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 今天的运动 前端控制器
 * </p>
 *
 * @author chen
 * @since 2024-03-08
 */
@RestController
@RequestMapping("/child-sport-records")
public class ChildSportRecordsController {
    @Autowired
    ChildSportRecordsService childSportRecordService;

    @GetMapping("")
    public List<ChildSportRecords> getSportRecords(ChildSportRecords foodinfo) {
        List<ChildSportRecords> objectList = childSportRecordService.list(new LambdaQueryWrapper<ChildSportRecords>().eq(foodinfo.getSport() != null, ChildSportRecords::getSport, foodinfo.getSport())

        );
        return objectList;
    }
    @PostMapping("")
    public boolean saveSportRecords(@RequestBody ChildSportRecords foodinfo) {

        return childSportRecordService.save(foodinfo);
    }
    @PutMapping ("")
    public boolean updateSportRecords(@RequestBody ChildSportRecords foodinfo){
        System.out.println("更新");
        return childSportRecordService.updateById(foodinfo);
    }
    @DeleteMapping  ("/{id}")
    public boolean DeleteSportRecords(@PathVariable("id") Long[] id) {

        return childSportRecordService.removeByIds(Arrays.asList(id));
    }
}

